From 6cbe94755387cc1943b1832533532f844ba4a5c1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 10 Aug 2014 21:48:43 -0700 Subject: [PATCH] Don't always print an error on test failures Only print a failure if the command didn't have an exit status. Also, clarify the failure message in the case that an exit was detected but it was not a successful status. Closes #350 --- src/bin/cargo-test.rs | 9 ++++----- src/cargo/util/process_builder.rs | 26 ++++++++++++++------------ tests/test_cargo_compile.rs | 4 ++-- tests/test_cargo_test.rs | 3 +-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/bin/cargo-test.rs b/src/bin/cargo-test.rs index cd1ce0e97..873c20eb0 100644 --- a/src/bin/cargo-test.rs +++ b/src/bin/cargo-test.rs @@ -56,11 +56,10 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult> { match err { None => Ok(None), Some(err) => { - let status = match err.exit { - Some(ExitStatus(i)) => i as uint, - _ => 101, - }; - Err(CliError::from_boxed(err.mark_human(), status)) + Err(match err.exit { + Some(ExitStatus(i)) => CliError::new("", i as uint), + _ => CliError::from_boxed(err.mark_human(), 101) + }) } } } diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index a0322e380..da88b33f4 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -59,34 +59,36 @@ impl ProcessBuilder { .stderr(InheritFd(2)) .stdin(InheritFd(0)); - let msg = || format!("Could not execute process `{}`", - self.debug_string()); - - let exit = try!(command.status().map_err(|e| - process_error(msg(), Some(e), None, None))); + let exit = try!(command.status().map_err(|e| { + process_error(format!("Could not execute process `{}`", + self.debug_string()), + Some(e), None, None) + })); if exit.success() { Ok(()) } else { - Err(process_error(msg(), None, Some(&exit), None)) + Err(process_error(format!("Process didn't exit successfully: `{}`", + self.debug_string()), + None, Some(&exit), None)) } } pub fn exec_with_output(&self) -> Result { let command = self.build_command(); - let msg = || format!("Could not execute process `{}`", - self.debug_string()); - let output = try!(command.output().map_err(|e| { - process_error(msg(), Some(e), None, None) + process_error(format!("Could not execute process `{}`", + self.debug_string()), + Some(e), None, None) })); if output.status.success() { Ok(output) } else { - Err(process_error(msg(), None, Some(&output.status), - Some(&output))) + Err(process_error(format!("Process didn't exit successfully: `{}`", + self.debug_string()), + None, Some(&output.status), Some(&output))) } } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index aee2b4e60..d5d3f0555 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -671,7 +671,7 @@ test!(custom_build_failure { "#); assert_that(p.cargo_process("cargo-build"), execs().with_status(101).with_stderr(format!("\ -Could not execute process `{}` (status=101)\n\ +Process didn't exit successfully: `{}` (status=101)\n\ --- stderr\n\ task '
' failed at 'nope', {filename}:2\n\ \n\ @@ -732,7 +732,7 @@ test!(custom_second_build_failure { "#); assert_that(p.cargo_process("cargo-build"), execs().with_status(101).with_stderr(format!("\ -Could not execute process `{}` (status=101)\n\ +Process didn't exit successfully: `{}` (status=101)\n\ --- stderr\n\ task '
' failed at 'nope', {filename}:2\n\ \n\ diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 2fb1b9772..1d551c6bc 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -147,8 +147,7 @@ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured sep = path::SEP)) .with_stderr(format!("\ task '
' failed at 'Some tests failed', [..] -Could not execute process `{test}[..]` (status=101) -", test = p.root().join("target/test/foo").display())) +")) .with_status(101)); }) -- 2.30.2